package com.borya.util;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class RabbitmqConfig extends PropertyUtils {

    private Logger log = Logger.getLogger(getClass());
    private static RabbitmqConfig instance = new RabbitmqConfig();

    private RabbitmqConfig() {
        String path = "/conf/rabbitmq.properties";
        try (InputStream is = RabbitmqConfig.class.getResourceAsStream("/application.properties")) {
            if (is != null) {
                Properties prop = load(is);
                final String profiles = prop.getProperty("spring.profiles.active");
                path = "/conf/rabbitmq-" + profiles + ".properties";
            }
        } catch (IOException ex) {
            // IGNORE
        }

        init(path, RabbitmqConfig.class);
        log.debug("load properties file," + path);
    }

    public static final RabbitmqConfig getInstance() {
        return instance;
    }
}
